package com.wink_172.activity

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import com.wink_172.commons.R
import com.wink_172.commons.databinding.ActivityAnimBinding
import com.wink_172.commons.databinding.ActivityDecimalFormatBinding
import com.wink_172.library.activity.SmartActivity
import com.wink_172.library.utils.DisplayUtil
import org.xutils.x
import java.math.BigDecimal
import java.text.DecimalFormat

/**
 * 数字处理集合
 * */
class DecimalFormatActivity : SmartActivity() {

    lateinit  var binding: ActivityDecimalFormatBinding

    companion object {
        @JvmStatic
        fun startActivity(context: Context, vararg args: Any?) {
            val intent = Intent(context, DecimalFormatActivity::class.java)

            //intent.putExtra(Constants.PARAM_DATA1, (String) args[0]);
            context.startActivity(intent)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = DataBindingUtil.setContentView(this, R.layout.activity_decimal_format)


        initView()
        init()
    }

    fun initView(){

    }

    fun init(){

        binding!!.text1!!.setText("" + DecimalFormat("0").format(300L) )

        binding!!.text2!!.setText("" +DecimalFormat("0.0").format(502.00))

        binding!!.text3.setText(""+DecimalFormat(",###").format(3256515021))

        binding!!.text4.setText("" +DecimalFormat("0.00").format(502f))

        binding!!.text5.setText("" +DecimalFormat("00").format(3))
        binding!!.text6.setText("" +DecimalFormat("000").format(3))
    }

    /**
     * 四舍五入，设置double，保留num位小数 */
    fun limitDouble2(d: Double, num: Int): String? {
        val d2 = String.format("%." + num + "f", d)
        return BigDecimal(d2).toString()
    }
}